package jdk.optional;

import jdk.entity.UserEntity;

import java.time.LocalDate;
import java.util.*;

/**
 * @author songyafei
 */
public class OptionTest1 {
    public static void main(String[] args) {
        UserEntity userEntity4 = new UserEntity(4L, 21, "song", LocalDate.now().minusYears(4));
        UserEntity userEntity5 = new UserEntity(5L, 32, "hao", LocalDate.now().minusYears(2));
        UserEntity userEntity6 = new UserEntity();
        UserEntity userEntity7 = null;
        List<UserEntity> userEntityList = new ArrayList<>();
        Map<String,UserEntity> userEntityMap = new HashMap<>(20);

        Optional.ofNullable(userEntity4).ifPresent(userEntityList::add);
        Optional.ofNullable(userEntity6).ifPresent(userEntityList::add);
        Optional.ofNullable(userEntity7).ifPresent(userEntityList::add);
        userEntityList.forEach(m-> System.out.println(m.toString()));
        System.out.println("-----------------");
        Optional.ofNullable(userEntity4).ifPresent(m->userEntityMap.put(m.getName(),m));
        Optional.ofNullable(userEntity6).ifPresent(m->userEntityMap.put(m.getName(),m));
        Optional.ofNullable(userEntity7).ifPresent(m->userEntityMap.put(m.getName(),m));
        Optional.ofNullable(userEntityMap).ifPresent(System.out::println);
    }
}
